<template>
  <div class="login-container">
    <div class="login-box">
      <h1>系统登录</h1>
      <form @submit.prevent="handleLogin">
        <div class="input-group">
          <label for="username">账号:</label>
          <input
            type="text"
            id="username"
            v-model="username"
            placeholder="请输入账号（初始：test）"
            required
          />
        </div>
        <div class="input-group">
          <label for="password">密码:</label>
          <input
            type="password"
            id="password"
            v-model="password"
            placeholder="请输入密码（初始：123）"
            required
          />
        </div>
        <button type="submit" class="login-button">登录</button>
      </form>
      <p v-if="errorMessage" class="error-message">{{ errorMessage }}</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'LoginPage',
  data() {
    return {
      username: 'test', // 默认账号为 test
      password: '123',  // 默认密码为 123
      errorMessage: '',
    };
  },
  methods: {
    handleLogin() {
      if (this.username === 'test' && this.password === '123') {
        // 登录成功，跳转到 SpiderPage
        this.$router.push('/spider');
      } else {
        // 登录失败，显示错误信息
        this.errorMessage = '账号或密码错误';
      }
      // 清空输入框
      this.username = '';
      this.password = '';
    },
  },
};
</script>

<style scoped>
.login-container {
  background: radial-gradient(circle at center, #0d1b2a, #1b263b);
  height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  position: fixed;
  top: 0;
  left: 0;
  overflow: hidden;
}

.login-box {
  background: rgba(0, 10, 30, 0.8);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 0 15px rgba(0, 150, 255, 0.5);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 150, 255, 0.3);
  width: 320px;
  text-align: center;
  position: relative;
}

h1 {
  font-size: 2rem;
  margin-bottom: 1.5rem;
  text-shadow: 0 0 10px rgba(0, 150, 255, 0.8);
}

.input-group {
  margin-bottom: 1.2rem;
}

label {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: bold;
  color: #8ecae6;
}

input {
  width: 100%;
  padding: 0.6rem;
  font-size: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.login-button {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  background: linear-gradient(90deg, #0096c7, #00b4d8);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease-in-out;
  text-shadow: 0 0 8px rgba(0, 150, 255, 0.8);
}

.login-button:hover {
  background: linear-gradient(90deg, #0077b6, #0096c7);
  box-shadow: 0 0 12px rgba(0, 150, 255, 0.8);
}

.error-message {
  margin-top: 1rem;
  color: #ff4d6d;
  text-shadow: 0 0 6px rgba(255, 77, 109, 0.8);
}

/* 添加科技感边框和线条 */
.login-box::before, .login-box::after {
  content: '';
  position: absolute;
  width: 40px;
  height: 40px;
  border: 2px solid rgba(0, 150, 255, 0.8);
}

.login-box::before {
  top: -10px;
  left: -10px;
  border-right: none;
  border-bottom: none;
}

.login-box::after {
  bottom: -10px;
  right: -10px;
  border-left: none;
  border-top: none;
}
</style>